package com.zzz.framework.config.advice;

import com.zzz.framework.exception.BizException;
import com.zzz.framework.model.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandle {

    @ExceptionHandler(Exception.class)
    public R handleException(Exception e) {
        if (e instanceof BizException) {
            BizException bizException = (BizException) e;
            return R.error(bizException.getMessage());
        } else {
            log.error("handleException", e);
            return R.error(e.getMessage());
        }

    }
}
